package srdb.migration.common;

import srdb.migration.Util.DBInfo;

import java.io.FileInputStream;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class JTDSConnection extends MTKConnection {
    private static String jtdsDriver = "net.sourceforge.jtds.jdbc.Driver";

    public JTDSConnection(String dbURL, String dbUser, String dbPassword)
            throws Exception {
        super(dbURL, dbUser, dbPassword);
        try {
            Class.forName(jtdsDriver);

            if (dbUser.indexOf("\\") > 0) {
                dbURL = dbURL + ";domain=" + dbUser.substring(0, dbUser.indexOf("\\"));
                dbUser = dbUser.substring(dbUser.indexOf("\\") + 1);
            }
            this.conn = DriverManager.getConnection(dbURL, dbUser, dbPassword);
        } catch (SQLException se) {
            throw new Exception(se.getMessage());
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
    }

    public JTDSConnection(String propertiesFile)
            throws Exception {
        super(propertiesFile);
        try {
            Properties ini = new Properties();
            ini.load(new FileInputStream(propertiesFile));

            this.dbURL = ini.getProperty("JTDSConnection");
            this.dbUser = ini.getProperty("JTDSUser");
            this.dbPassword = ini.getProperty("JTDSPassword");

            Class.forName(jtdsDriver);

            this.conn = DriverManager.getConnection(this.dbURL, this.dbUser, this.dbPassword);
        } catch (SQLException se) {
            throw new Exception(se.getMessage());
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
    }


    @Override
    public boolean preConnectDB(String[] parms) throws Exception {
        //todo
        return false;
    }
}

/* 

 * 
 */